import {SIZE} from './config';
import {fn} from './index';

const {desktop} = SIZE;

export const get_w_h = (_this) => {
  const {top, left, bottom, height, width} = (_this && _this.getBoundingClientRect()) || {};
  return {
    offsetWidth: () => document.documentElement.offsetWidth,
    offsetHeight: () => document.documentElement.offsetHeight,
    scrollTop: () => document.documentElement.scrollTop,
    top,
    left,
    bottom,
    height,
    width
  }
}

export const setConfirm = (modalDom, top, left) => {
  const {offsetWidth} = get_w_h();
  if (offsetWidth() < desktop) {
    fn.modalInit(modalDom)
    return;
  }
  modalDom.style.top = top + 63 + 'px';
  modalDom.style.left = left - 38 + 'px';
  modalDom.style.transform = 'translate3D(0,0,0)';
}

export const isPreventScroll = () => {
  return {
    hidden: () => document.body.style['overflow-y'] = 'hidden',
    auto: () => document.body.style['overflow-y'] = 'auto',
  };
}

export const hideModal = (layer) => {
  layer.classList.add('hide')
  // isPreventScroll().auto()
}

